/**
 *  产品规格选择
 */
define(function(require,exports,module) {
    var myPub = require('./public');
    var SumEvent = require('./sum');
    var oTaxDelArea = $('.js_taxDelArea');                      // 显示税费区域
    var oTaxDel = $('.js_taxDel');                              // 显示税费数字
    var taxPriceNum = 0;                                        // 税费金额
    var taxRate = 0;                                            // 税费单价
    var oGoodsPrice = $('#salePrice');                          // 价格处
    var nPrice = 0;                                             // 当前单价
    GoodsSizeSelet();
    function GoodsSizeSelet() {
        var oGoodsSizeSide = $('.js_goodsSizeSide'); 		    // 全部弹层
        var oMoreSizeSide = $('.js_moreSizeSide'); 		        // 多规格框
        var oFixedSizeSide = $('.js_fixedSizeSide'); 		    // 任选规格
        var oSumNum = $('.js_sumNum');                          //总数

        var oSeletNumBtn = $('.js_seletNumBtn');                // 规格选择数量提示按钮
        var oOKBtn = $('.js_OKBtn');                            // 确定按钮

        var oCloseSideBtn = $('.js_closeSideBtn');              // 关闭按钮
        var oShadow = $('.js_shadow');				            // 阴影
        var oShowIntro = $('.js_showIntro');				    // 送礼介绍

        var oSideScroll_moreSize = new myPub.ScrollBar();               // 规格滚动条
        var oSideScroll_fixedSize = new myPub.ScrollBar();              // 规格滚动条

        var giftOrder = "";//送他订单
        var layerStyle = 'background-color:rgba(255,255,255,1); color:#252525; border:none; border-radius: 5px; min-width: 50%';


        if(oMoreSizeSide.length > 0) {
            oSideScroll_moreSize.AddScroll(oMoreSizeSide.find('.js_goodsSizeList')[0]);
        }
        else if (oFixedSizeSide.length > 0) {
            oSideScroll_fixedSize.AddScroll(oFixedSizeSide.find('.js_goodsSizeList')[0]);
        }



        var moveHeight = oGoodsSizeSide.outerHeight(true);    	// 弹框高度
        oGoodsSizeSide.css({'bottom': -moveHeight });

        var oSellMemberId = $('#sellMemberId');                 // 丰享sellMemberId
        
        var buynowSuper = $('#buynow_super_id');
        var index_oGoodsSize = 0;

        oGoodsSizeSide.on("touchmove",function(e) {e.preventDefault()});

        // 关闭按钮关闭弹层
        oCloseSideBtn.hammer().on('tap', function () {
            $('.js_sumNum').blur();
            oGoodsSizeSide.stop().animate({'bottom': -moveHeight}, 250, function () {
                oGoodsSizeSide.hide();
                oShadow.hide();
                oOKBtn.removeClass('act_joinCar act_payMust');
                if(typeof mui !== 'undefined'){
                    myPub.OffMuiEvent(true);
                }
            });
            oShowIntro.hide();
            myPub.HamstopPropaga();
        });

        //阴影关闭
        oShadow.hammer().on('tap',function() {
            $('.js_sumNum').blur();
            oGoodsSizeSide.stop().animate({'bottom': -moveHeight}, 250, function () {
                oGoodsSizeSide.hide();
                oShadow.hide();
                oOKBtn.removeClass('act_joinCar act_payMust');

                if(typeof mui !== 'undefined'){
                    myPub.OffMuiEvent(true);
                }

            });
            oShowIntro.hide();
            myPub.HamstopPropaga();
        });

        var seletSize = {
            init: function () {
                var _this = this;
                _this.initEvent();
            },

            initEvent: function () {
                var _this = this;
                var oGoodsSize = $('.js_goodsSize');                // 选择规格入口
                // var index_oGoodsSize = 0;
                oGoodsSize.hammer().off('tap');
                oGoodsSize.hammer().on('tap', function () {
                    var index = oGoodsSize.index($(this));
                    $('.js_sumNum').blur();
                    index_oGoodsSize = index;
                    // 购物车列表
                    if($(this).parents('li').hasClass('act_showSeletSize')) {
                        var $this = $(this);
                        var cartId = $this.parents('li').attr("cartitemid");
                        var productId = $this.parents('li').attr("productId");
                        var price = $this.parents('li').find('.js_goodsPrice').text();
                        var sumNum = $this.parents('li').find('.js_sumNum').val();

                        _this.setLayerData($this,cartId,productId,price,sumNum,function (iavPathArrays,specProductDates,productDatas) {
                            _this.JudgeSizeSide($this,iavPathArrays,specProductDates,productDatas);
                        });
                        oOKBtn.removeClass('act_joinCar act_payMust');
                    }
                    else {
                        if(typeof mui !== 'undefined'){
                            myPub.OffMuiEvent(false);
                        }
                        // 加入购物车
                        if($(this).hasClass('act_joinCar')) {
                            _this.JudgeSizeSide($(this));
                            oOKBtn.addClass('act_joinCar');
                        }
                        // 立即购买
                        else if ($(this).hasClass('act_payMust')){
                            _this.JudgeSizeSide($(this));
                            oOKBtn.addClass('act_payMust');
                            //送他
                            if($(this).hasClass('js_giftOrder')){
                                giftOrder = 1;
                                // if(obj.hasClass('act_moreSize')) {
                                // oMoreSizeSide
                                oShowIntro.show();
                            }else{
                                giftOrder = 0;
                            }
                        }
                    }

                    myPub.HamstopPropaga();

                    return index_oGoodsSize;
                });


                // 确定按钮
                oOKBtn.hammer().off('tap');
                oOKBtn.hammer().on('tap', function () {
                    // var $this = $(this);
                    //当商品无货时  关闭按钮点击
                    if(tapFlag){
                        return;
                    }

                    var $this = $(this);
                    if($this.hasClass('act_payMust') || $this.hasClass('act_joinCar') ){
                        if(getLiParentHtml() == false){
                            return;
                        }
                    }

                    var $parent = $this.parents('.js_goodsSizeSide');
                    var _price = $parent.find('.js_goodsSmallImg .js_goodsPrice').text();
                    var _size =  $parent.find('.js_goodsSmallImg .js_user_seleted span').text();
                    var _num = $parent.find('.js_sumNum').val();
                    var _img = $('#currentImg').attr('src');
                    if(_num === undefined) _num = 1;


                    oGoodsSizeSide.stop().animate({'bottom': -moveHeight}, 250, function () {
                        if($this.hasClass('act_joinCar')) {
                            oOKBtn.removeClass('act_joinCar act_payMust');
                            // 加入购物车
                            var quantity = $("#quantity").val();

                            if(selectedProductId == "" || selectedProductId == undefined){
                                selectedProductId = $("#selectedProductId").val();
                            }

                            G_JSON_POST('/shop/cartItem/addCart', {
                                "pId": selectedProductId,
                                "quantity": quantity,
                                "goodschannel": goodschannel,
                                "liveId": liveId,
                                "regionId": regionId
                            }, function (data) {
                                if (data.status == "success") {
                                    var cartCount = data.cartCount;

                                    myPub.OffMuiEvent(true);
                                    myPub.TipLayer('加入购物车成功！', layerStyle);

                                    if( typeof setActionData != 'undefined' ) {
                                        console.log(setActionData)
                                        // 添加用户行为
                                        // var setActionDatas = {};
                                        setActionData.pid = selectedProductId * 1;
                                        setActionData.num = quantity * 1;
                                        // setActionDatas.requestid = recRequestId;
                                        // if( goodschannel == 'datagrand' || goodschannel == 'not_datagrand' ){
                                        //     setActionDatas.scenetype = 'cate';
                                        // }

                                        userAction(oOKBtn, 'cart', setActionData);
                                    }


                                    $.ajax({
                                        type: "POST",
                                        url: "/shop/cartItem/getCount",
                                        dataType: "json",
                                        success: function (data) {
                                            if (data.count != 0) {
                                                $(".js_userNum").show();
                                                $('.js_userNum').html(data.count);
                                            } else {
                                                $('.js_userNum').hide();
                                            }
                                        },
                                        error: function (textStatus) {
                                            if (textStatus.status == 403) {
                                                $('.js_userNum').hide();
                                            }
                                        },
                                        complete: function (XHR) {
                                            XHR = null;
                                        }
                                    });
                                } else {
                                    myPub.TipLayer(data.message);
                                }
                            });
                            oGoodsSizeSide.hide();
                            oShadow.hide();
                        }
                        // 立即购买
                        else if ($this.hasClass('act_payMust')){
                            var nchooseNum = $('.js_sumNum').val()*1;       // 现在选中的数量
                            if(xgCount!=0 && xgCount < nchooseNum){
                                myPub.TipLayer("超出限购数量"+xgCount+"件，无法立即购买");
                                oGoodsSizeSide.hide();
                                oShadow.hide();
                                return
                            }

                            // 只针对顺丰速运商品，如限购10件 已购买了5件 这时的orderCount就是5
                            if(orderCount!=0 && orderCount < nchooseNum){
                                myPub.TipLayer("您现在最多只能购买"+xgCount+"件哦~");
                                oGoodsSizeSide.hide();
                                oShadow.hide();
                                return
                            }

                            myPub.OffMuiEvent(true);
                            oOKBtn.removeClass('act_joinCar act_payMust');

                            var productIds =[];
                            if($this.hasClass('js_flowerMulti')){
                                //任选商品点击的id    鲜花任选结算
                                $(".js_goodsSizemob").find("li.active").each(function(i){
                                    var temval = $(".js_goodsSizemob").find("li.active").eq(i).attr("id");
                                    productIds.push(temval);
                                });
                                //工具的id
                                $(".js_otherSize").find("li.active").each(function(i){
                                    var temval = $(".js_otherSize").find("li.active").eq(i).attr("id");
                                    productIds.push(temval);
                                });

                                // // 添加用户行为
                                // var setActionDatas = [];
                                // setActionDatas.pid = selectedProductId * 1;
                                // setActionDatas.num = quantity * 1;
                                // for(var i=0; i<productIds.length; i++) {
                                //     setActionDatas[i] = {};
                                //     setActionDatas[i].pid = productIds[i] * 1;
                                //     setActionDatas[i].num = 1;
                                // }
                                // userAction(productIds, 'buy', setActionDatas);

                                window.location.href = '/shop/pay/buynowMulti?productIds='+productIds;
                                oGoodsSizeSide.hide();
                                oShadow.hide();
                            }
                            else{
                                if(selectedProductId == "" || selectedProductId == undefined){
                                    selectedProductId = $("#selectedProductId").val();
                                }

                                var groupCountParam = '';
                                if( typeof countStatus != 'undefined' && typeof goodsGroupId != 'undefined'){
                                    if( countStatus !='' && countStatus == 'true' && goodsGroupId != '' ){
                                        groupCountParam = '&countStatus='+countStatus+'&goodsGroupId='+goodsGroupId;
                                    }
                                }

                                //立即购买参数验证  及其购买操作  单规格  多规格 结算
                                var quantity = $("#quantity").val();

                                // // 添加用户行为
                                // var setActionDatas = {};
                                // setActionDatas.pid = selectedProductId * 1;
                                // setActionDatas.num = quantity * 1;
                                // userAction(oOKBtn, 'buy', setActionDatas);

                                if(giftOrder == 1){
                                    //埋点
                                    try {
                                        var nowTime = new Date();
                                        nowTime = myPub.FormatDateTime(nowTime, null);
                                        console.log(nowTime);
                                        gio("track", "click_songta", {songtaclicktime: nowTime});
                                    } catch (e) {
                                        console.log("growIngIo 送他埋点上报数据异常")
                                    }
                                    // 送礼功能
                                    if(quantity>1){//如果数量大于1，那么挑起选择送礼方式弹层
                                        var oGiftSend_TypeSelet = $('.js_giftSend_TypeSelet');      // 送礼方式弹层
                                        var oTypeSeletList = $('.js_typeSeletList');                // 送礼方式选择
                                        var oTypeSeletIntro_layer = $('.js_typeSeletIntro_layer');  // 送礼方式说明
                                        if(oSellMemberId.val()!=undefined){
                                            oTypeSeletList.find('a.oneGift').attr('href','/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&sellMemberId='+oSellMemberId.val()+'&giftOrder=1&liveId='+liveId+'&regionId='+regionId);
                                            oTypeSeletList.find('a.multiGift').attr('href','/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&sellMemberId='+oSellMemberId.val()+'&giftOrder=2&liveId='+liveId+'&regionId='+regionId);
                                        }
                                        else{
                                            oTypeSeletList.find('a.oneGift').attr('href','/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&goodschannel='+goodschannel+'&recRequestId='+recRequestId+'&sceneType='+sceneType+'&giftOrder=1&liveId='+liveId+'&regionId='+regionId);
                                            oTypeSeletList.find('a.multiGift').attr('href','/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&goodschannel='+goodschannel+'&recRequestId='+recRequestId+'&sceneType='+sceneType+'&giftOrder=2&liveId='+liveId+'&regionId='+regionId);
                                        }
                                        oGoodsSizeSide.hide();
                                        oShadow.hide();
                                        oShadow.show();
                                        oGiftSend_TypeSelet.show();
                                        oTypeSeletList.show();
                                        oTypeSeletIntro_layer.hide();
                                    }
                                    else{
                                        if(oSellMemberId.val()!=undefined){
                                            window.location.href = '/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&sellMemberId='+oSellMemberId.val()+'&giftOrder='+giftOrder+'&liveId='+liveId+'&regionId='+regionId;
                                        }else{
                                            window.location.href = '/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&goodschannel='+goodschannel+'&recRequestId='+recRequestId+'&sceneType='+sceneType+'&giftOrder='+giftOrder+'&liveId='+liveId+'&regionId='+regionId+groupCountParam+"&kcuid="+kcuid;
                                        }
                                        oGoodsSizeSide.hide();
                                        oShadow.hide();
                                        oShowIntro.hide();
                                    }
                                }
                                else{
                                    if(oSellMemberId.val()!=undefined){
                                        window.location.href = '/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&sellMemberId='+oSellMemberId.val()+'&giftOrder='+giftOrder+'&liveId='+liveId+'&regionId='+regionId+groupCountParam;
                                    }else{
                                        if (buynowSuper.val() == 1){
                                            window.location.href = '/super/buynow_super?productIdAndquantity='+selectedProductId+','+quantity;
                                        }else{

                                            // 针对顺丰速运商品 判断顺丰速运的纯积分产品 积分不足时弹窗提示
                                            if(sfMember && sfMember == "changwenSB" && productDatasGoodsDetail && productDatasGoodsDetail[selectedProductId].memberPrice && (productDatasGoodsDetail[selectedProductId].memberPrice <= 0) && memberScore && (memberScore >= 0) ){
                                                var memberCoin = $this.parents('.js_moreSizeSide').find('.js_goodsSizemob').find('li.active').attr('costmemberscore')*1;
                                                var costCoin = 0;
                                                var myCoin = memberScore*1;
                                                if(memberCoin && memberCoin>0){
                                                    costCoin = memberCoin*quantity*1;
                                                    if(costCoin > myCoin){
                                                        myPub.TipLayer('您的积分不足，无法兑换！', 'no');
                                                        oGoodsSizeSide.hide();
                                                        oShadow.hide();
                                                        return
                                                    }
                                                }
                                            }else if(memberScore && (memberScore == -1)){
                                                myPub.TipLayer('您的积分不足，无法兑换！', 'no');
                                                oGoodsSizeSide.hide();
                                                oShadow.hide();
                                                return
                                            }

                                            window.location.href = '/shop/pay/buynow?productIdAndquantity='+selectedProductId+','+quantity+'&goodschannel='+goodschannel+'&recRequestId='+recRequestId+'&sceneType='+sceneType+'&giftOrder='+giftOrder+'&liveId='+liveId+'&regionId='+regionId+groupCountParam+"&kcuid="+kcuid;
                                        }
                                    }
                                    oGoodsSizeSide.hide();
                                    oShadow.hide();
                                }
                            }
                        }
                        // 购物车列表
                        else {

                            var cartId = oGoodsSize.eq(index_oGoodsSize).parents('li').attr("cartitemid");
                            var productId = oGoodsSize.eq(index_oGoodsSize).parents('li').attr("productId");
                            var oSumPrice = $('.js_sumPrice');                                                  //总价格
                            var oTaxSum = $('.js_taxSum');                                                      // 总的税费
                            if(selectedProductId == "" || selectedProductId == undefined){
                                selectedProductId = productId;
                            }

                            G_JSON_POST("/shop/cartItem/changeProduct",{"productId":selectedProductId,"quantity":_num,"cartId":cartId},function (data) {

                                if(data.status = "success"){
                                    var newCartId = data.obj.newCartId;
                                    oGoodsSize.eq(index_oGoodsSize).find('.js_sizeShow').text(_size);
                                    oGoodsSize.eq(index_oGoodsSize).parents('.js_carListArea').find('.js_goodsPrice').text(_price).attr('pprice',_price);
                                    oGoodsSize.eq(index_oGoodsSize).parents('.js_carListArea').find('.js_sumNum').val(_num);
                                    oGoodsSize.eq(index_oGoodsSize).parents('.js_carListArea').find('.js_lazyImg ').attr('src',_img);
                                    oGoodsSize.eq(index_oGoodsSize).parents('li').attr("productId",selectedProductId);
                                    oGoodsSize.eq(index_oGoodsSize).parents('li').attr("cartitemid",newCartId);

                                    // 修改税费
                                    var oTaxrateCar = oGoodsSize.eq(index_oGoodsSize).parents('li').find('.js_taxDelCar');
                                    if(oTaxrateCar && oTaxrateCar.length>0){
                                        var nTaxrateCar = oTaxrateCar.attr("taxrate")*1;
                                        oTaxrateCar.html((nTaxrateCar*_num).toFixed(2));
                                    }

                                    // 总的税费
                                    myPub.ShopSumPrice($('.js_carList').find('.js_checkBox'),'.js_carListArea','.js_taxDelCar',oTaxSum);

                                    // 总的价格
                                    myPub.ShopSumPrice($('.js_carList').find('.js_checkBox'),'.js_carListArea','.js_goodsPrice',oSumPrice);

                                }
                            });
                            oGoodsSizeSide.hide();
                            oShadow.hide();
                        }


                    });
                    myPub.HamstopPropaga();
                })

            },
            // 购物车列表点击出现弹层获的数据
            setLayerData: function (obj,cartId,productId,price,sumNum,fn) {
                var _this = this;
                var product = null;
                getSelectProduct(productId, function (data) {
                    product = data;
                    if(obj.hasClass('act_moreSize')) {
                        // oMoreSizeSide
                        G_JSON_POST("/shop/cartItem/getSkuData",{"cartItemId":cartId},function (data) {
                            if("success" == data.status){
                                //拼接规格页面
                                var goods = data.obj.goods;//商品信息
                                var goodsSpecMap = data.obj.goodsSpecMap;//属性信息
                                var productList = data.obj.productList;//属性列表
                                var type = "DGG";
                                var iavPathArrays =[];
                                var specProductDates={};//多规格 iavPath
                                var productDatas = {};//单规格  productId
                                for(var index in productList){
                                    if(productList[index].iavPath != ""){
                                        specProductDates[productList[index].iavPath]={
                                            store:productList[index].cbuyStore,
                                            salePrice:productList[index].salePrice.toFixed(2),
                                            memberPrice:productList[index].memberPrice.toFixed(2),
                                            memberCostScore:productList[index].costMemberScore,
                                            productId:productList[index].id,
                                            name:productList[index].name,
                                            imgPath:HTTP_IMAGE_URL+productList[index].imgPath
                                        }
                                    }
                                }
                                for(var index in productList){
                                    iavPathArrays.push(productList[index].iavPath);
                                }

                                for(var index in productList){
                                    productDatas[productList[index].id]={
                                        store:productList[index].cbuyStore,
                                        salePrice:productList[index].salePrice.toFixed(2),
                                        memberPrice:productList[index].memberPrice.toFixed(2),
                                        memberCostScore:productList[index].costMemberScore,
                                        name:productList[index].name,
                                        imgPath:HTTP_IMAGE_URL+productList[index].imgPath
                                    }
                                }

                                //idArrays = product.iavPath.split(",");
                                var html = appendSkuPage(goods,goodsSpecMap,productList,product,type,price,sumNum);
                                oMoreSizeSide.find('.js_appendSKU').empty().append(html);
                                oSideScroll_moreSize.DelScroll();
                                oSideScroll_moreSize.AddScroll(oMoreSizeSide.find('.js_goodsSizeList')[0]);
                                SumEvent.SumPriceEvent();
                                seletSize.initEvent();
                                if(fn)fn(iavPathArrays,specProductDates,productDatas);
                            }
                        });
                    }
                    else if(obj.hasClass('act_fixedSize')) {
                        // oFixedSizeSide
                    }

                });

            },


            // 判断显示弹框选择
            JudgeSizeSide: function (obj,iavPathArrays,specProductDates,productDatas) {
                var _this = this;
                if(obj.hasClass('act_moreSize')) {
                    oMoreSizeSide.show().stop().animate({'bottom': 0}, 250, function () {
                        oSideScroll_moreSize.ReScroll();
                        _this.moreSize(iavPathArrays,specProductDates,productDatas);
                    });
                }
                else if(obj.hasClass('act_fixedSize')) {
                    oFixedSizeSide.show().stop().animate({'bottom': 0}, 250, function () {
                        oSideScroll_fixedSize.ReScroll();
                        _this.fixedSize(flowerNumber);
                    });
                }
                oShadow.show();
            },

            // 多规格选择
            moreSize: function (iavPathArrays,specProductDates,productDatas) {

                if(iavPathArrays == undefined){
                    iavPathArrays = iavPathArraysGoodsDetail;
                }
                if(specProductDates == undefined){
                    specProductDates = specProductDatesGoodsDetail;
                }
                if(productDatas == undefined){
                    productDatas = productDatasGoodsDetail;
                }

                var _this = this;
                var GoodsSizemob = oMoreSizeSide.find('.js_goodsSizemob');
                var oUser_seleted = oMoreSizeSide.find('.js_user_seleted');

                _this.moreSizeInit(GoodsSizemob, oUser_seleted,iavPathArrays,specProductDates);

                GoodsSizemob.find('li').hammer().off('tap');
                GoodsSizemob.find('li').hammer().on('tap', function () {
                    var _num = GoodsSizemob.length;
                    var _parent = $(this).parents('.js_goodsSizemob');
                    var parentIndex = _parent.index();
                    var _countLi = _parent.find('li');
                    var index = _countLi.index($(this));
                    if($(this).hasClass('active-over')) {
                        myPub.TipLayer("该商品已经没有库存啦~");
                    }
                    else {
                        _countLi.removeClass('active').eq(index).addClass('active');
                        _this.moreSizeInit(GoodsSizemob, oUser_seleted,iavPathArrays,specProductDates);


                        //获取多规格 id数组
                        iavPath ="";//使用前初始化
                        //getIdArray($(this),parentIndex);

                        // 表示全部选择了规格 需要获取 库存
                        if(GoodsSizemob.find('li.active').length === _num) {
                            if(_num > 1){
                                getMultiProductStock($(this),parentIndex,iavPathArrays,specProductDates);
                                $(this).parents('.js_goodsSizeSide ').find('.js_sumNum ').val(1)
                            }else{
                                getStock($(this),productDatas);
                                $(this).parents('.js_goodsSizeSide ').find('.js_sumNum ').val(minNum)
                            }
                        }
                    }
                    myPub.HamstopPropaga();
                });

            },

            // 任选规格
            fixedSize: function (num) {
                var _this = this;
                var aList = [];
                var aListName = [];
                var aOtherName = [];
                var GoodsSizemob = oFixedSizeSide.find('.js_goodsSizemob');
                var oUser_seleted = oFixedSizeSide.find('.js_user_seleted');
                var oTherSize = oFixedSizeSide.find('.js_otherSize');
                num = parseInt(num);

                _this.fixedSizeInit(GoodsSizemob, aList);

                // 规格选择
                GoodsSizemob.find('li').hammer().off('tap');
                GoodsSizemob.find('li').hammer().on('tap', function () {
                    var _countLi = GoodsSizemob.find('li');
                    var index = _countLi.index($(this));

                    if($(this).hasClass('active-over')) {
                        myPub.TipLayer("该商品已经没有库存啦~");
                        return;
                    }
                    else {

                        if($(this).hasClass('active')) {
                            $(this).removeClass('active');

                            myPub.removeArrayChildren(aList,index);
                            myPub.removeArrayChildren(aListName,$(this).text());
                        }
                        else {
                            $(this).addClass('active');
                            aList.push(index);
                            aListName.push($(this).text());
                            if(aList.length > num) {
                                aList.splice(0, 1);
                                aListName.splice(0, 1);
                                _countLi.removeClass('active');
                                for (var i=0; i<aList.length; i++) {
                                    _countLi.eq(aList[i]).addClass('active');
                                }
                            }
                        }

                        if(aList.length === num) {
                            oSeletNumBtn.hide();
                            oOKBtn.show();
                        }
                        else {
                            oSeletNumBtn.show().text('还可以选择'+ (num - aList.length) +'件');
                            oOKBtn.hide();
                        }

                        oUser_seleted.find('.js_seletSize').text(aListName);
                        //改变价格和库存
                        getStock($(this),productDatasGoodsDetail);
                    }
                    myPub.HamstopPropaga();
                });


                // 工具选择
                oTherSize.find('li').hammer().off('tap');
                oTherSize.find('li').hammer().on('tap', function () {
                    if($(this).hasClass('active-over')) {
                        myPub.TipLayer("该商品已经没有库存啦~");
                    }
                    else {
                        if($(this).hasClass('active')) {
                            $(this).removeClass('active');
                            myPub.removeArrayChildren(aOtherName,$(this).text());
                        }
                        else {
                            $(this).addClass('active');
                            aOtherName.push($(this).text());
                        }
                       oUser_seleted.find('.js_seletOther').text(aOtherName);
                        //改变价格和库存
                        getStock($(this),productDatasGoodsDetail);
                    }
                    myPub.HamstopPropaga();
                });

            },

            // 获取库存和价格  单规格
            getStock: function (target) {},

            // 任选初始化数组
            fixedSizeInit: function (GoodsSizemob,array) {
                if(GoodsSizemob.find('li.active').length > 0) {
                    var _activeLi = GoodsSizemob.find('li.active');
                    _activeLi.each(function (i) {
                        array.push(GoodsSizemob.find('li').index(_activeLi.eq(i)));
                    });
                    return array
                }
            },
            // 多规格初始化
            moreSizeInit: function (GoodsSizemob, oUser_seleted,iavPathArrays,specProductDates) {
                var _aActName = [];
                idArrays = [];//使用前初始化一次
                if(GoodsSizemob.find('li.active').length > 0) {
                    var _activeLi = GoodsSizemob.find('li.active');
                    _activeLi.each(function (i) {
                        _aActName.push(_activeLi.eq(i).text());

                        //将详情页的默认规格选择以后加入idArrays
                        idArrays.push(_activeLi.eq(i).attr('value'));
                    });

                    //console.log("%o  %o  %o",idArrays,iavPathArrays,specProductDates);
                    if(GoodsSizemob.find('li.active').length === GoodsSizemob.length && GoodsSizemob.length > 1) {
                        getMultiProductStock(null,null,iavPathArrays,specProductDates);
                        // 检查是否需要灰选
                        var iavGroup = {};
                        GoodsSizemob.each(function () {
                            var $goodsSizeDiv = $(this);
                            var groupId = $goodsSizeDiv.attr('id');
                            $goodsSizeDiv.find('li').each(function () {
                                var $li = $(this);
                                var liId = $li.attr("value");
                                iavGroup[liId] = groupId;
                            });
                        });
                        var iavArrays = [];
                        /*
                        for(var idx=0;idx<iavPathArrays.length;idx++){
                            var ivaPath = iavPathArrays[idx];
                            var ivaArray = ivaPath.split(",");
                            iavArrays.push(ivaArray);
                        }
                        */
                        for(var ivaPath in specProductDates){
                            var specProductDate = specProductDates[ivaPath];
                            if(specProductDate.store <= 0){
                                continue;
                            }
                            var ivaArray = ivaPath.split(",");
                            iavArrays.push(ivaArray);
                        }
                        GoodsSizemob.find('li').each(function () {
                            var $li = $(this);
                            var liId = $li.attr("value");
                            var match = false;
                            for(var idx=0;idx<iavArrays.length;idx++){
                                var ivaArray = iavArrays[idx];
                                if($.inArray(liId,ivaArray) == -1){
                                    continue;
                                }
                                var otherMatch = true;
                                for(var jj=0;jj<idArrays.length;jj++){
                                    var id = idArrays[jj];
                                    if(iavGroup[liId] == iavGroup[id]){
                                        continue;
                                    }
                                    if($.inArray(id,ivaArray) == -1){
                                        otherMatch = false;
                                        break;
                                    }
                                }
                                if(otherMatch){
                                    match = true;
                                }
                            }
                            if(match){
                                $li.removeClass('active-over');
                            }else{
                                $li.addClass('active-over');
                            }
                        });

                    }
                    oUser_seleted.find('.js_seletSize').text(_aActName)
                }

            }

        }

        seletSize.init();
    }

    //商品最小购买数量
    var goodschannel = $("#goodschannel").val();
    var recRequestId = $("#recRequestId").val();
    var sceneType = $("#sceneType").val();
    var regionId=$('#regionId').length>0?$('#regionId').val():"";

    var flowerNumber = $("#flowerNumber").val();
    var minNum = 1;
    var minCount = $('.jsMinCount');
    var selectedProductId = "";
    if(minCount.attr("minCount") != null && minCount.attr("minCount") != undefined){
        minNum = parseInt(minCount.attr("minCount"));
    }


    // 初始化税费
    if(oTaxDelArea && oTaxDelArea.length > 0){
        taxRate = oTaxDelArea.parents('.js_chooseNumArea').siblings('.js_goodsSizeList').find('li.active').attr('taxfare');
        if(taxRate && taxRate != undefined && taxRate!=''){
            taxRate = taxRate*1*minNum;
        }else{
            taxRate = 0;
        }
        oTaxDel.text('￥'+taxRate.toFixed(2));
    }else{
        taxRate = 0;
    }

    // 获取库存和价格  单规格
    function getStock(target,productDatas) {
        var $thisId = target.attr("id");

        var oTaxDelArea = $('.js_taxDelArea');                      // 显示税费区域
        var oTaxDel = $('.js_taxDel');                              // 显示税费数字
        var taxPriceNum = 0;                                        // 税费金额
        var taxRate = 0;                                            // 税费单价

        // if ($thisId == selectedProductId) {
        //     return false;
        // }
        $("#quantity").val(minNum);
        selectedProductId = $thisId;

        // 税费
        if(oTaxDelArea && oTaxDelArea.length > 0){
            taxRate = target.parents('.js_goodsSizeList').find('li.active').attr('taxfare');
            if(taxRate && taxRate != undefined && taxRate!=''){
                taxRate = taxRate*1;
            }else{
                taxRate = 0;
            }
        }else{
            taxRate = 0;
        }

        //变更库存
        $(".kucun").attr("value", productDatas[selectedProductId].store);
        $(".kucun").html(productDatas[selectedProductId].store);

        //规格值
        $(".hasChoose").attr("value", productDatas[selectedProductId].name);
        $(".hasChoose").html(productDatas[selectedProductId].name);
        var oDefaultFanxian=$(".js_default_fanxian");
        var oHJmember=$("#HJmember").val();
        if($('#costMemberScore').length > 0){
            // 税费
            taxPriceNum = (minNum*taxRate).toFixed(2)*1;
            oTaxDel.text('￥'+taxPriceNum.toFixed(2));

            $("#salePrice").attr("pprice", productDatas[selectedProductId].memberPrice);
            $("#salePrice").html((productDatas[selectedProductId].memberPrice*minNum).toFixed(2));
            $("#costMemberScore").html(productDatas[selectedProductId].memberCostScore*minNum);
            $("#costMemberScore").attr("costMemberScore",productDatas[selectedProductId].memberCostScore);
            if(productDatas[selectedProductId].isReturnMoney=="true" &&productDatas[selectedProductId].returnMoneyPercentage!=null && productDatas[selectedProductId].saleModel!=1  ){
                if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                    oDefaultFanxian.show();
                }
                $("#returnMoney").html((productDatas[selectedProductId].returnMoneyPercentage*productDatas[selectedProductId].memberPrice*minNum/100).toFixed(2));
                $("#salePrice").attr("returnMoneyPercentage",productDatas[selectedProductId].returnMoneyPercentage);
            }else{
                if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                    oDefaultFanxian.hide();
                }
                $("#salePrice").removeAttr("returnMoneyPercentage");
            }


        }else {
            // 税费
            taxPriceNum = (minNum*taxRate).toFixed(2)*1;
            oTaxDel.text('￥'+taxPriceNum.toFixed(2));

            $("#salePrice").attr("pprice", productDatas[selectedProductId].salePrice);
            if(productDatas[selectedProductId].isJifen=="true" && productDatas[selectedProductId].memberPoint > 0){
                if(productDatas[selectedProductId].salePrice == 0){
                    $("#salePrice").html(productDatas[selectedProductId].memberPoint*minNum+'积分');
                }else{
                    $("#salePrice").html((productDatas[selectedProductId].salePrice*minNum).toFixed(2)+'+'+productDatas[selectedProductId].memberPoint*minNum+'积分');
                    if(productDatas[selectedProductId].isReturnMoney=="true" &&productDatas[selectedProductId].returnMoneyPercentage!=null && productDatas[selectedProductId].saleModel!=1  ){
                        if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                            oDefaultFanxian.show();
                        }
                        $("#returnMoney").html((productDatas[selectedProductId].returnMoneyPercentage*productDatas[selectedProductId].salePrice*minNum/100).toFixed(2));
                        $("#salePrice").attr("returnMoneyPercentage",productDatas[selectedProductId].returnMoneyPercentage);
                    }else{
                        if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                            oDefaultFanxian.hide();
                        }
                        $("#salePrice").removeAttr("returnMoneyPercentage");
                    }

                }
                $("#salePrice").attr("jifen", productDatas[selectedProductId].memberPoint);
            }else{

                //购物返现
                if(productDatas[selectedProductId].isReturnMoney=="true" &&productDatas[selectedProductId].returnMoneyPercentage!=null && productDatas[selectedProductId].saleModel!=1  ){
                    if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                        oDefaultFanxian.show();
                    }
                    $("#salePrice").html((productDatas[selectedProductId].salePrice*minNum).toFixed(2));
                    $("#salePrice").attr("returnMoneyPercentage",productDatas[selectedProductId].returnMoneyPercentage);
                    $("#returnMoney").html((productDatas[selectedProductId].returnMoneyPercentage*minNum*productDatas[selectedProductId].salePrice/100).toFixed(2));
                }else{
                    if(oDefaultFanxian.length>0 && oHJmember == "HJmember"){
                        oDefaultFanxian.hide();
                    }
                    if(productDatas[selectedProductId].saleModel==1){
                        $("#salePrice").html(productDatas[selectedProductId].salePrice);
                    }else{
                        $("#salePrice").html((productDatas[selectedProductId].salePrice*minNum).toFixed(2));
                    }

                    $("#salePrice").removeAttr("returnMoneyPercentage");
                }

                $("#salePrice").removeAttr("jifen");
            }
        }

        if(productDatas[selectedProductId].imgPath != HTTP_IMAGE_URL && productDatas[selectedProductId].imgPath != HTTP_IMAGE_URL+"null"){
            $("#currentImg").attr("src", productDatas[selectedProductId].imgPath);
            $("#currentImg").html(productDatas[selectedProductId].imgPath);
        }

    }
    // 获取库存和价格  多规格
    var tapFlag = false;
    var idArrays=[];
    // var specLength = oneIavPth.split(",").length;//默认商品 iavpath剪切后的长度
    var iavPath = "";//product的iavPath属性
    function getIdArray(obj,specIndex) {

        if(idArrays.length>=specIndex){
            idArrays.splice(specIndex,1,obj.val());
        }else{
            for(var i=0;i<specIndex;i++){
                idArrays.push(0);
            }
            idArrays.splice(specIndex,1,obj.val());
        }
    }


    //获取多规格未选择的li父级html
    function getLiParentHtml() {
        var obj = $('.js_goodsSizemob');
        var objLeng = $('.js_goodsSizemob[id]').length;
        for(var i=0; i<=objLeng-1;i++){
            var objP = $('.js_goodsSizemob[id ='+i+']  p').text();
            var objLi = $('.js_goodsSizemob[id ='+i+'] li');
            if(!objLi.hasClass('active')){
                myPub.TipLayer('请选择商品'+objP);
                return false;
            }
        }
    }
    function getMultiProductStock(obj,specIndex,iavPathArrays,specProductDates) {

        iavPath = "";
        // idArrays.length == specLength &&
        if( ($.inArray(0,idArrays) == -1)){
            //拼接选中的规格 id
            for(var i=0;i<idArrays.length;i++){
                if(i<idArrays.length-1){
                    iavPath += idArrays[i]+",";
                }else{
                    iavPath += idArrays[i];
                }

            }

            //当iavPath与后台参数一致的时候  进行下列逻辑
            iavPath = isInclude(iavPath,iavPathArrays);

            if(iavPath != ""){
                selectedProductId = specProductDates[iavPath].productId;
                if(specProductDates[iavPath].store > 0){
                    $(".kucun").attr("value", specProductDates[iavPath].store);
                    $(".kucun").html(specProductDates[iavPath].store);

                    //规格值
                    $(".hasChoose").attr("value", specProductDates[iavPath].name);
                    $(".hasChoose").html(specProductDates[iavPath].name);

                    $(".js_OKBtn").removeClass("btn_Bghui btn_Bggray");
                    tapFlag = false;
                    $(".js_OKBtn").html('确定');
                }else{
                    $(".kucun").attr("value", 0);
                    $(".kucun").html(0);

                    //规格值
                    $(".hasChoose").attr("value", specProductDates[iavPath].name);
                    $(".hasChoose").html(specProductDates[iavPath].name);

                    $(".js_OKBtn").addClass('btn_Bghui btn_Bggray');
                    if($(".js_OKBtn").hasClass("btn_Bggray")){
                        tapFlag = true;
                    }
                    $(".js_OKBtn").html('无货');
                }
                if($('#costMemberScore').length > 0){
                    $("#salePrice").attr("pprice", specProductDates[iavPath].memberPrice);
                    $("#salePrice").html(specProductDates[iavPath].memberPrice);
                    $("#costMemberScore").html(specProductDates[iavPath].memberCostScore);
                }else {
                    $("#salePrice").attr("pprice", specProductDates[iavPath].salePrice);
                    if(specProductDates[iavPath].isJifen=="true"&& specProductDates[iavPath].memberPoint > 0){
                        if(specProductDates[iavPath].salePrice == 0){
                            $("#salePrice").html(specProductDates[iavPath].memberPoint+'积分');
                        }else{
                            $("#salePrice").html(specProductDates[iavPath].salePrice+'+'+specProductDates[iavPath].memberPoint+'积分');
                        }
                        $("#salePrice").attr("jifen", specProductDates[iavPath].memberPoint);
                    }else{
                        $("#salePrice").html(specProductDates[iavPath].salePrice);
                        $("#salePrice").removeAttr("jifen");
                    }
                }

                if(specProductDates[iavPath].imgPath != HTTP_IMAGE_URL && specProductDates[iavPath].imgPath != HTTP_IMAGE_URL+"null"){
                    $("#currentImg").attr("src", specProductDates[iavPath].imgPath);
                    $("#currentImg").html(specProductDates[iavPath].imgPath);
                }

                //选择规格时，计数清零
                // $('.js_sumNum').val(1);


            }else{
                $(".js_OKBtn").addClass('btn_Bghui btn_Bggray');
                if($(".js_OKBtn").hasClass("btn_Bggray")){
                    tapFlag = true;
                }
                $(".js_OKBtn").html('无货');
                $(".kucun").attr("value", 0);
                $(".kucun").html(0);
                selectedProductId = -1;
            }


        }
    }


    //拼接弹出层SKU页面
    function appendSkuPage(goods,goodsSpecMap,productList,product,type,price,sumNum) {

        var html = '';
        var sfMemberHtml = '';
        if(goods.memberPrice == "true"){
            if(product.costMemberScore >0){
                sfMemberHtml = '<span class="goodsPrice js_goodsPrice" id="salePrice" pprice="'+product.memberPrice+'">'+price+'</span>'+
                    '<span class="color_hui jsGoodsCostMemberScore" style="margin-left: 0.5rem">+<span id="costMemberScore">'+product.costMemberScore+'</span>积分</span>';
            }
        }else{
            sfMemberHtml = ' <span id="salePrice" class="goodsPrice js_goodsPrice"  pprice="'+product.salePrice+'">'+price+'</span>';
        }

        var skuChooseHtml = '';
        if(goods.isSpecificationEnabled){
            var itemAttrKeyHtml = getItemAttrKeyHtml(goodsSpecMap,product);
            skuChooseHtml = '<section class="goodsSizeList js_goodsSizeList VBox Bflex1">'+
                '<section class="goodsSizeBox js_goodsSizeBox Bflex1" >'+
                itemAttrKeyHtml+
                '</section></section>';
        }else{
            var productListHtml = getProductListHtml(productList,product);
            skuChooseHtml = '<section class="goodsSizeList js_goodsSizeList VBox Bflex1">'+
                '<section class="goodsSizeBox js_goodsSizeBox Bflex1" >'+
                '<div class="goodsSizemob js_goodsSizemob" id="0">'+
                '<p class="sideTitle">规格选择:</p>'+
                '<ul class="Bflex1 clearfix">'+
                productListHtml+
                '</ul></div></section></section>'
        }


        var chooseNumHtml =  getChooseNumHtml(goods,sumNum);

        var productImg ;
        var defaultImage = getDefaultImage(goods);
        if(product.imgPath!=null && product.imgPath!=''){
            productImg = product.imgPath;
        }else{
            productImg = defaultImage;
        }



        if("RX" == type){

        }else{
            // 添加商品税费区域
            var taxHtml = '';
            for(var index in productList){
                if((productList[index].id == product.id) && productList[index].calGlobalFee && productList[index].calGlobalFee != null && productList[index].cbuyStore > 0){
                    var nTaxRare = (productList[index].calGlobalFee*sumNum).toFixed(2);
                    taxHtml = '   <div class="buyGoodsNum HBox spBe flexBox taxDelArea js_taxDelArea">'+
                        '       <div>商品税费</div>'+
                        '       <div class="js_taxDel" >￥'+nTaxRare+'</div>'+
                        '   </div>';
                }else{
                    taxHtml = ''
                }
            }
            html = '<section class="goodsSmallImg js_goodsSmallImg HBox BoxCenter">'+
                '       <figure class="goodsImg ">'+
                '           <img id="currentImg" src="'+HTTP_IMAGE_URL+''+productImg+ smallImgArg200 +'" alt="">'+
                '       </figure>'+
                '<div class="Bflex1">'+
                '<p class="priceAreaBox">'+
                '<i class="units">￥</i>'+
                sfMemberHtml+
                '</p>'+
                '<p class="">库存：<span class="kucun" value="'+product.cbuyStore+'">'+product.cbuyStore+'</span>份</p>'+
                '<p class="user_seleted js_user_seleted">已选择：<span class="hasChoose" value="'+product.name+'">'+product.name+'</span></p>'+
                '</div></section>'+
                skuChooseHtml+
                '<div class="transnationalTax js_chooseNumArea">'+
                '   <section class="buyGoodsNum HBox BoxCenter ">'+
                '       <p class="sideTitle Bflex1">请选择数量</p>'+
                '       <div class="amountBox HBox js_amountBox BoxCenter ">'+
                            chooseNumHtml+
                '       </div>'+
                '   </section>'+
                    // BC清关
                    taxHtml+
                '</div>' +
                '</section>';

            return html;
        }
    }


    /**
     * 获取默认规格
     */
    // function getOneProduct(goods){
    //     for(var index in goods.productList){
    //         if(goods.productList[index].isDefault){
    //             return goods.productList[index];
    //         }
    //     }
    //     return goods.productList[0];
    // }

    /**
     * 获取选中规格
     */
    function getSelectProduct(productId, fn) {
        G_JSON_POST("/shop/cartItem/getSelectProduct",{"productId":productId},function (data) {
            if(data.status = "success"){
                if(fn) fn(data.obj)
            }
        });
    }


    /**
     * 获取默认图片
     * @param goods
     * @returns {*}
     */
    function getDefaultImage(goods) {
        if(goods.goodsImagePath != ''){
            var defaultImage = goods.goodsImagePath.split(',');
            return defaultImage[0];
        }
        return '';
    }

    //多规格拼接属性名
    function getItemAttrKeyHtml(goodsSpecMap,product) {
        var html = '';
        var index = 0;
        for(var itemKey in goodsSpecMap){
            var itemAttrValueHtml = getItemAttrValueHtml(goodsSpecMap[itemKey],product);
            var jsonItemKey = JSON.parse(itemKey);
            html += '<div class="goodsSizemob js_goodsSizemob" id="'+index+'">'+
                '<p class="sideTitle" value="'+jsonItemKey.id+'">'+jsonItemKey.iakName+':</p>'+
                '<ul class="Bflex1 clearfix">'+
                itemAttrValueHtml+
                '</ul></div>'
            index++;
        }
        return html;
    }


    //多规格拼接属性值
    function getItemAttrValueHtml(itemAttrValueList,product) {

        var iavPath = product.iavPath.split(',');
        var html = '';
        for(var index in itemAttrValueList){

            if($.inArray(itemAttrValueList[index].id+"", iavPath) != -1){
                html += '<li class="active" value="'+itemAttrValueList[index].id+'" >'+itemAttrValueList[index].iavValue+'</li>'
            }else{
                html += '<li value="'+itemAttrValueList[index].id+'" >'+itemAttrValueList[index].iavValue+'</li>'
            }
        }
        return html;
    }


    //单规格拼接SKU
    function getProductListHtml(productList,product) {

        var html = '';
        for(var index in productList){
            if(productList[index].id==product.id && productList[index].cbuyStore > 0){
                if(productList[index].cbuyStore == 0){
                    html += '<li  class="active" taxFare="'+productList[index].calGlobalFee+'" id="'+productList[index].id+'"  mutliStore="'+productList[index].cbuyStore+'"  class="active-over">'+productList[index].name+'</li>'
                }else{
                    html += '<li  class="active" taxFare="'+productList[index].calGlobalFee+'" id="'+productList[index].id+'"  mutliStore="'+productList[index].cbuyStore+'" >'+productList[index].name+'</li>'
                }

            }else{
                if(productList[index].cbuyStore == 0){
                    html += '<li taxFare="'+productList[index].calGlobalFee+'" id="'+productList[index].id+'"  mutliStore="'+productList[index].cbuyStore+'" class="active-over" >'+productList[index].name+'</li>'
                }else{
                    html += '<li taxFare="'+productList[index].calGlobalFee+'" id="'+productList[index].id+'"  mutliStore="'+productList[index].cbuyStore+'"  >'+productList[index].name+'</li>'
                }
            }
        }
        return html;
    }

    //拼接弹出层数量
    function getChooseNumHtml(goods,sumNum) {
        var html = '';
        var minCount = goods.minCount;
        var maxCount = goods.xgCount;
        if(minCount!='' && minCount!=undefined && minCount<1){
            minCount = 1;
        }
        if(goods.xgCount==1 || goods.goodsLabels=="WEIXIN_NEW_USER" || goods.goodsLabels=="NWE_USER"){
            html = '<button class="numBtn js_handBtn active" type="button">-</button>'+
                '<input  id="quantity" class="sumNum js_sumNum jsMinCount" type="number" name="" minCount = "'+minCount+'" maxCount = "'+maxCount+'" value="1"  readOnly="true"/>'+
                '<button class="numBtn js_handBtn" type="button">+</button>'
        }else{
            html = '<button class="numBtn js_handBtn active" type="button">-</button>'+
                '<input  id="quantity" class="sumNum js_sumNum jsMinCount" type="number" name="" minCount = "'+minCount+'"  maxCount = "'+maxCount+'" value="'+sumNum+'" />'+
                '<button class="numBtn js_handBtn" type="button">+</button>'
        }
        return html;
    }


    /**
     * 获取iavPath
     * @param {Object} ivaPath 88,89,90,92,91
     * @param {Object} ivaPathArray ["88,89,90,91,92", "88,89,90,91,93"]
     */
    function isInclude(ivaPath,ivaPathArray){
        if(ivaPathArray && ivaPath){
            var ivasLen = ivaPathArray.length;
            if(ivasLen == 0){
                return "";
            }
            var ivaPaths = ivaPath.split(','),
                ivaPathsLen = ivaPaths.length,
                ivaPathsLenjj = ivaPathsLen - 1;
            for (var i = 0; i < ivasLen; i++) {
                var	ivaPathA = ivaPathArray[i],
                    ivaPathArrays = ivaPathA.split(','),
                    ivaPathArraysLen = ivaPathArrays.length;

                var isIncludeArray = false;
                for (var j = 0; j < ivaPathsLen; j++) {
                    var isIncludeArrays = false;
                    for (var a = 0; a < ivaPathArraysLen; a++) {
                        if(ivaPaths[j]==ivaPathArrays[a]){
                            isIncludeArrays = true;
                            break;
                        }
                    }
                    if(isIncludeArrays==false){
                        break;
                    }else{
                        if(j == ivaPathsLenjj && isIncludeArrays){
                            isIncludeArray = isIncludeArrays;
                            break;
                        }
                    }
                }
                if(isIncludeArray == true){
                    return ivaPathArray[i];
                }
            }
        }
        return "";
    }


    // 添加用户行为
    function userAction(obj, mode, keyword) {
        ddjhoc.setData(obj, mode, 'add', function () {
            console.log('params.'+mode, ddjhoc.params);
            ddjhoc.sendData( ddjhoc.params );
        }, keyword);
    }

    exports.GoodsSizeSelet = GoodsSizeSelet;
});